<template>
    <transition name="drop">
        <div class="top-tip" v-show="showFlag">
            <slot>
            </slot>
        </div>
    </transition>
</template>

<script>
export default {
  props: {
    delay: {
      type: Number,
      default: 1000
    }
  },
  data() {
    return {
      showFlag: false,
      timer: {}
    };
  },
  methods: {
    show() {
      this.showFlag = true;
      clearTimeout(this.timer);
      this.timer = setTimeout(() => {
        this.hide();
      }, this.delay);
    },
    hide() {
      this.showFlag = false;
    }
  }
};
</script>

<style scoped lang="stylus" rel="stylesheet/stylus">
@import '~common/stylus/variable';

.top-tip {
  position: fixed;
  top: 50%;
  padding: 10px 20px;
  z-index: 500;
  left: 50%;
  transform: translate(-50%, -50%);
  background: $color-background-d;
  color: $color-background;

  &.drop-enter-active, &.drop-leave-active {
    transition: all 0.3s;
  }

  &.drop-enter, &.drop-leave-to {
    transform: translate3d(-50%, -100%, 0);
  }
}
</style>
